package com.example.mvc.controller;

import com.example.mvc.bean.History;
import com.example.mvc.bean.User;
import com.example.mvc.service.BookBorrowService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.util.List;

//还书
@WebServlet("/bookReturnServlet")
public class BookReturnServlet extends HttpServlet {
  BookBorrowService bookBorrowService = new BookBorrowService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String returnBookId = req.getParameter("returnBookId");
        int count =bookBorrowService.bookReturn(Integer.parseInt(returnBookId));
        String contextPath = req.getContextPath();
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        int status = user.getStatus();
        if (status!=1){//管理员
            resp.sendRedirect(contextPath+"/bookBorrowListServlet");
        }else {//普通用户
            resp.sendRedirect(contextPath+"/borrowListByUserServlet");
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
